package cn.sciento.boot.tenant.dto;

import java.util.Date;
import java.util.Objects;
import org.apache.commons.lang3.builder.ToStringBuilder;
import cn.sciento.boot.tenant.constant.TenantInitProcessorType;
import cn.sciento.boot.tenant.constant.TenantInitStatus;
import cn.sciento.boot.tenant.constant.TenantInitType;
import org.springframework.beans.BeanUtils;

public class TenantInitLogDTO extends TenantInitConfigDTO {
  private String tenantNum;
  
  private TenantInitStatus processStatus;
  
  private Date processTime;
  
  private String processMessage;
  
  private String instanceKey;
  
  public TenantInitLogDTO() {}
  
  public TenantInitLogDTO(String serviceName, String processorCode, String processorName, TenantInitProcessorType processorType, TenantInitType initType, Integer orderSeq, String remark, String tenantNum, TenantInitStatus processStatus, Date processTime, String processMessage) {
    super(serviceName, processorCode, processorName, processorType, initType, orderSeq, remark);
    this.tenantNum = tenantNum;
    this.processStatus = processStatus;
    this.processTime = processTime;
    this.processMessage = processMessage;
  }
  
  public static TenantInitLogDTO buildInstance(TenantInitConfigDTO tenantInitConfigDTO, TenantInitContext tenantInitContext) {
    TenantInitLogDTO tenantInitLog = new TenantInitLogDTO();
    BeanUtils.copyProperties(tenantInitConfigDTO, tenantInitLog);
    if (tenantInitContext == null)
      return tenantInitLog; 
    tenantInitLog.setTenantNum(tenantInitContext.getTenantNum());
    tenantInitLog.setProcessTime(new Date());
    tenantInitLog.setInstanceKey(tenantInitContext.getInstanceKey());
    return tenantInitLog;
  }
  
  public String getTenantNum() {
    return this.tenantNum;
  }
  
  public TenantInitLogDTO setTenantNum(String tenantNum) {
    this.tenantNum = tenantNum;
    return this;
  }
  
  public TenantInitStatus getProcessStatus() {
    return this.processStatus;
  }
  
  public TenantInitLogDTO setProcessStatus(TenantInitStatus processStatus) {
    this.processStatus = processStatus;
    return this;
  }
  
  public Date getProcessTime() {
    return this.processTime;
  }
  
  public TenantInitLogDTO setProcessTime(Date processTime) {
    this.processTime = processTime;
    return this;
  }
  
  public String getProcessMessage() {
    return this.processMessage;
  }
  
  public TenantInitLogDTO setProcessMessage(String processMessage) {
    this.processMessage = processMessage;
    return this;
  }
  
  @Override
  public String toString() {
    return (new ToStringBuilder(this))
      .append("tenantNum", this.tenantNum)
      .append("processStatus", this.processStatus)
      .append("processTime", this.processTime)
      .append("processMessage", this.processMessage)
      .toString();
  }
  
  public String getInstanceKey() {
    return this.instanceKey;
  }
  
  public void setInstanceKey(String instanceKey) {
    this.instanceKey = instanceKey;
  }
  
  @Override
  public boolean equals(Object o) {
    if (this == o)
      return true; 
    if (!(o instanceof TenantInitLogDTO))
      return false; 
    if (!super.equals(o))
      return false; 
    TenantInitLogDTO that = (TenantInitLogDTO)o;
    return (Objects.equals(this.tenantNum, that.tenantNum) && this.processStatus == that.processStatus && 
      
      Objects.equals(this.processTime, that.processTime) && 
      Objects.equals(this.processMessage, that.processMessage) && 
      Objects.equals(this.instanceKey, that.instanceKey));
  }
  
  @Override
  public int hashCode() {
    return Objects.hash(super.hashCode(), this.tenantNum, this.processStatus, this.processTime, this.processMessage, this.instanceKey);
  }
}
